﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Derrick.AttackTest
{
    public partial class SelectDevice : Form
    {
        private int _editRowIndex = 0;

        public SelectDevice()
        {
            InitializeComponent();
            //devicesForCapturingBindingSource.DataSource = SharedStorage.Instance.DevicesForCapturing;
            _deviceGridView.DataSource = SharedStorage.Instance.DevicesForCapturing;
            _deviceGridView.CellBeginEdit += new DataGridViewCellCancelEventHandler(_deviceGridView_CellBeginEdit);
            
        }

        public void SetDataSource(schemaAttack.DevicesForCapturingDataTable deviceTable)
        {
            _deviceGridView.DataSource = deviceTable;
        }            

        void _deviceGridView_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs args)
        {
            //throw new NotImplementedException();
            if (args.ColumnIndex == 3)
            {
                _editRowIndex = args.RowIndex;
                //_captureFileDialog.ShowDialog();
            }
        }

        


        private void _selectButton_Click(object sender, EventArgs e)
        {
            SharedStorage.Instance.DevicesForCapturing.AcceptChanges();
            Close();
        }

        private void _captureFileDialog_FileOk(object sender, CancelEventArgs args)
        {
            SharedStorage.Instance.DevicesForCapturing[_editRowIndex].CaptureFile = _captureFileDialog.FileName;
            //_deviceGridView.Rows[_editRowIndex][3] = _captureFileDialog.FileName;
            //DataGridViewLinkCell linkCell = _deviceGridView.Rows[_editRowIndex][3] as DataGridViewLinkCell;
            DataGridViewRow currentRow = _deviceGridView.Rows[_editRowIndex];
            DataGridViewButtonCell currentButton = currentRow.Cells[3] as DataGridViewButtonCell;
            currentButton.UseColumnTextForButtonValue = true;
        }

        private void _deviceGridView_CellContentClick(object sender, DataGridViewCellEventArgs args)
        {
           // _captureFileDialog.ShowDialog();
            
        }


    }
}
